<script setup lang="ts">
import type { ArticleVO } from '@/types/vo/ArticleVO'
import type { LabelVO } from '@/types/vo/LabelVO'

const { Article, Label } = defineProps<{
  Article: ArticleVO
  Label?: LabelVO | undefined
}>()

const router = useRouter()
const onClick = () => {
  const {href} = router.resolve({
    path: '/article/ArticleDetail',
    query: {
      articleId: Article.id
    }
  });
  window.open(href, '_blank')
}
</script>

<template>
  <div>
    <div class="article-item" @click="onClick">
      <div class="article-item-title">
        {{ Article.articleName }}
      </div>
      <div class="flex gap-5px items-center">
        <n-avatar
          :src="Article.authorAvatar"
          round
          size="small"
          class="w-20px h-20px"
        />
        <span>{{ Article.author }}</span>
      </div>
      <div class="text-ellipsis" v-html="Article.description"></div>
      <div class="flex items-center gap-2px">
        <i-custom-liked width="20px" />
        <span v-if="Article.likedCount" class="font-size-12px"
          >({{ Article.likedCount }})</span
        >
        <div class="bg-#4096ff px-4px rounded ml-auto c-white font-size-12px">
          {{ Label?.labelName }}
        </div>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.article-item {
  width: 100%;
  margin-bottom: 10px;
  padding: 6px;
  border-bottom: 2px solid #f3f4f6;
  cursor: pointer;
  &:hover {
    background-color: #f7f8fa;
  }
  .article-item-title {
    font-size: 14px;
    color: #333;
    font-weight: 700;
  }
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.text-ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  -webkit-line-clamp: 3;
  display: -webkit-box;
  -webkit-box-orient: vertical;
}
</style>
